package com.gaoyi.websocket.common;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

import java.io.Serializable;

@Data
@JsonInclude(value= JsonInclude.Include.NON_NULL)
public class ServerResponse<T> implements Serializable {
    protected Integer code;
    protected String message;
    protected T data;
    public static  final  Integer SUCCESS_CODE = 200;
    public static  final String SUCCESS_MSG = "SUCCESS";
    public static  final  Integer FAIL_CODE = 300;

    public ServerResponse(Integer returnCode, String returnMsg, T data) {
        this.code = returnCode;
        this.message = returnMsg;
        this.data = data;
    }

    public static  <T> ServerResponse<T> success(){
        return new ServerResponse(SUCCESS_CODE,SUCCESS_MSG,null);
    }

    public static  <T> ServerResponse<T> error(){
        return new ServerResponse(FAIL_CODE,"服务器内部错误,请联系管理员",null);
    }

    public static  <T> ServerResponse<T> successResponse(T data){
        return new ServerResponse(SUCCESS_CODE,SUCCESS_MSG,data);
    }

    public static  <T> ServerResponse<T> errorResponse(Integer code, String msg, T data){
        return new ServerResponse(code,msg,data);
    }

    public static  <T> ServerResponse<T> errorMessage(String msg){
        return new ServerResponse(FAIL_CODE,msg,null);
    }

//    @JSONField(deserialize = false)
//    public boolean  isSuccess(){
//        return StringUtils.equals(SUCCESS_CODE,returnCode);
//    }
}
